package tenant

import (
	"context"

	v1 "gitee.com/liangziyisheng/caas-platform-mc/api/tenant/v1"
	"gitee.com/liangziyisheng/caas-platform-mc/internal/service"
)

func (c *ControllerV1) List(ctx context.Context, req *v1.ListReq) (res *v1.ListRes, err error) {
	in := &v1.ListInput{}
	in.Code = req.Code
	in.Name = req.Name
	in.Status = req.Status
	in.Page = req.Page
	in.Size = req.Size
	out, err := service.Tenant().List(ctx, in)
	if err != nil {
		return nil, err
	}
	res = &v1.ListRes{Total: out.Total, Data: make([]v1.Tenant, 0)}
	for _, v := range out.Data {
		t := v1.Tenant{
			Id:           v.Id,
			Name:         v.Name,
			Code:         v.Code,
			Address:      v.Address,
			Contact:      v.Contact,
			Phone:        v.Phone,
			CountryCode:  v.CountryCode,
			ProvinceCode: v.ProvinceCode,
			CityCode:     v.CityCode,
			CountyCode:   v.CountyCode,
			Status:       v.Status,
		}
		res.Data = append(res.Data, t)
	}
	return res, nil
}
